package com.test.demo.enums;

import lombok.Getter;

@Getter
public enum StatusEnum {
    /**
     * 状态
     */
    NORMAL(0, "正常"),
    ABNORMAL(1, "异常"),
    ;

    private int code;
    private String name;

    StatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取名称
     *
     * @param code
     * @return
     */
    public static String getNameByCode(int code) {
        StatusEnum[] enums = StatusEnum.values();
        for (StatusEnum e : enums) {
            if (e.getCode() == code) {
                return e.getName();
            }
        }
        return "";
    }
}
